package com.brillilab.message.consumer;

import com.alibaba.fastjson.JSONObject;
import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import com.brillilab.common.rocketmq.UsersCacheVo;
import com.brillilab.message.handler.MessageHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author zlb
 * @Title: OnsClusteringCrmListener
 * @ProjectName brill_lab
 * @Description: TODO
 * @date 2019/11/28 11:19
 */
@Component
public class OnsClusteringCrmListener implements MessageListener {
    public static MessageHandler messageHandler;
    private static Logger logger = LoggerFactory.getLogger(OnsClusteringCrmListener.class);

    @Override
    public Action consume(Message message, ConsumeContext context) {
        // 此处可以写具体业务逻辑，body是具体发送的内容
        try {
            UsersCacheVo userCacheVo = JSONObject.parseObject(new String(message.getBody()), UsersCacheVo.class);
            messageHandler.handlerModifyUserCache(userCacheVo);
            return Action.CommitMessage;
        } catch (Exception e) {
            logger.info("modifyUserCache-Err:" + e.getMessage());
            return Action.CommitMessage;
        }
    }
}
